/* GUI CONVERTED from reshmtb1.p (converter v1.76) Wed May 22 11:22:52 2002 */
/* reshmtb1.p - Repetitive Subcontract Shipper Maintenance subprogram         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.3.3.4 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3    LAST MODIFIED: 10/31/94           BY: WUG *GN77*          */
/* REVISION: 7.3    LAST MODIFIED: 11/09/94           BY: WUG *GO39*          */
/* REVISION: 7.3    LAST MODIFIED: 07/11/96 BY: *G1ZT* Julie Milligan         */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98 BY: *K1Q4* Alfred Tan             */
/* REVISION: 9.1    LAST MODIFIED: 10/25/99 BY: *N002* Bill Gates             */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00 BY: *N0KP* Mark Brown             */
/* REVISION: 9.1    LAST MODIFIED: 09/14/00 BY: *L13V* Vandna Rohira          */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.3.3.4 $    BY: Jean Miller       DATE: 05/15/02  ECO: *P05V*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}

define input parameter abs_recid as recid.
define input parameter wolot as character.
define input parameter op as integer.
define input parameter part as character.
define input parameter trans_um as character.
define input parameter trans_conv like sod_um_conv.

define shared variable h_wiplottrace_procs as handle no-undo.
define shared variable h_wiplottrace_funcs as handle no-undo.

define variable old_gwt like pt_net_wt.
define variable new_gwt like pt_net_wt.
define variable old_nwt like pt_net_wt.
define variable new_nwt like pt_net_wt.
define variable old_vol like abs_vol.
define variable new_vol like abs_vol.
define variable wt_conv as decimal.
define variable vol_conv as decimal.
define variable i as integer.
define variable temp_recid as recid.
define variable new_mfguser as character no-undo.
define variable msg-arg     as character format "x(12)" no-undo.

define buffer abs_mstr_item for abs_mstr.
define buffer abs_mstr_child for abs_mstr.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i}

new_mfguser = mfguser + global_db.

find abs_mstr where recid(abs_mstr) = abs_recid exclusive-lock.

assign
   old_vol = 0
   old_gwt = 0
   old_nwt = 0.

for first wo_mstr where wo_lot = wolot
no-lock: end.

for each abs_mstr_item exclusive-lock
   where abs_mstr_item.abs_shipfrom = abs_mstr.abs_shipfrom
     and abs_mstr_item.abs_par_id = abs_mstr.abs_id
     and abs_mstr_item.abs_id begins "i"
     and abs_mstr_item.abs_order = wolot
     and abs_mstr_item.abs_line = string(op)
     and abs_mstr_item.abs_item = part:

   if is_wiplottrace_enabled() then do:
      run delete_abs_wip_lot_children
         (input abs_mstr_item.abs_shipfrom,
          input abs_mstr_item.abs_id).
   end.

   assign
      old_vol = old_vol + abs_vol
      old_gwt = old_gwt + abs_gwt
      old_nwt = old_nwt + abs_nwt.

   delete abs_mstr_item.

end.

assign
   i = 0
   new_nwt = 0
   new_gwt = 0
   new_vol = 0.

for each sr_wkfl exclusive-lock
   where sr_userid = new_mfguser:
/*GUI*/ if global-beam-me-up then undo, leave.


   i = i + 1.

   create abs_mstr_item.
   assign
      abs_mstr_item.abs_shipfrom = abs_mstr.abs_shipfrom
      abs_mstr_item.abs_id = "i" + abs_mstr.abs_id +
                             string(wolot,"x(8)") + string(op,"9999") +
                             string(part,"x(18)") + string(i,"9999")
      abs_mstr_item.abs_par_id = abs_mstr.abs_id
      abs_mstr_item.abs_item = part
      abs_mstr_item.abs_site = sr_site
      abs_mstr_item.abs_loc = sr_loc
      abs_mstr_item.abs_lotser = sr_lotser
      abs_mstr_item.abs_ref = sr_ref
      abs_mstr_item.abs_qty = sr_qty
      abs_mstr_item.abs_dataset = "wr_route"
      abs_mstr_item.abs_order = wolot
      abs_mstr_item.abs_line = string(op)
      abs_mstr_item.abs_type = "u".

   temp_recid = recid(abs_mstr_item).

   find pt_mstr where pt_part = abs_mstr_item.abs_item
   no-lock no-error.

   if available pt_mstr then do:

      if abs_mstr.abs_wt_um = "" then
         abs_mstr.abs_wt_um = pt_net_wt_um.

      if abs_mstr.abs_vol_um = "" then
         abs_mstr.abs_vol_um = pt_dim_um.

      wt_conv = 1.

      if pt_net_wt_um <> abs_mstr.abs_wt_um then do:
         {gprun.i ""gpumcnv.p""
            "(input pt_net_wt_um, input abs_mstr.abs_wt_um,
              input abs_mstr.abs_item, output wt_conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      if wt_conv = ? then do:
         /* Unable to convert weight UM for item/from UM/to UM */
         msg-arg = pt_part + " " + pt_net_wt_um + " " + abs_mstr.abs_wt_um.
         {pxmsg.i &MSGNUM=8225 &ERRORLEVEL=3 &MSGARG1=msg-arg}
         undo, retry.
      end.

      vol_conv = 1.

      if pt_dim_um <> abs_mstr.abs_vol_um then do:
         {gprun.i ""gpumcnv.p""
            "(input pt_dim_um, input abs_mstr.abs_vol_um,
              input abs_mstr.abs_item, output vol_conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      if wt_conv = ? then do:
         /* Unable to convert volumne UM for item/from UM/to UM */
         msg-arg = pt_part + " " + pt_dim_um + " " + abs_mstr.abs_vol_um.
         {pxmsg.i &MSGNUM=8226 &ERRORLEVEL=3 &MSGARG1=msg-arg}
         undo, retry.
      end.

      assign
         abs_mstr_item.abs_wt_um = abs_mstr.abs_wt_um
         abs_mstr_item.abs_nwt = pt_net_wt * wt_conv * abs_mstr_item.abs_qty
         abs_mstr_item.abs_gwt = pt_ship_wt * wt_conv * abs_mstr_item.abs_qty
         abs_mstr_item.abs_vol_um = abs_mstr.abs_vol_um
         abs_mstr_item.abs_vol = (pt_width * pt_height * pt_length) *
                                 vol_conv * abs_mstr_item.abs_qty.

      if abs_mstr_item.abs_gwt < abs_mstr_item.abs_nwt then
         abs_mstr_item.abs_gwt = abs_mstr_item.abs_nwt.
   end.

   if is_wiplottrace_enabled()
      and is_operation_queue_lot_controlled(wo_lot, op, INPUT_QUEUE)
   then do:
      run create_abs_wip_lot_children in h_wiplottrace_procs
         (input abs_mstr_item.abs_shipfrom,
          input abs_mstr_item.abs_id,
          input wo_lot,
          input op,
          input trans_conv).
   end.

   delete sr_wkfl.

   new_nwt = new_nwt + abs_mstr_item.abs_nwt.
   new_gwt = new_gwt + abs_mstr_item.abs_gwt.
   new_vol = new_vol + abs_mstr_item.abs_vol.

   assign
      abs_mstr_item.abs__qad02 = trans_um
      abs_mstr_item.abs__qad03 = string(trans_conv).

end.
/*GUI*/ if global-beam-me-up then undo, leave.


assign
   abs_mstr.abs_vol = abs_mstr.abs_vol - old_vol + new_vol
   abs_mstr.abs_gwt = abs_mstr.abs_gwt - old_gwt + new_gwt
   abs_mstr.abs_nwt = abs_mstr.abs_nwt - old_nwt + new_nwt.

PROCEDURE delete_abs_wip_lot_children:
   define input parameter ip_shipfrom like abs_shipfrom no-undo.
   define input parameter ip_parent_abs_id like abs_id no-undo.

   for each abs_mstr_child exclusive-lock
      where abs_shipfrom = ip_shipfrom
        and abs_par_id = ip_parent_abs_id:
      delete abs_mstr_child.
   end.
END PROCEDURE.
